﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel.Channels;
using System.ServiceModel.Dispatcher;
using System.Text;
using NHibernate.Linq;

namespace NhJump.Persistence.Context.WcfBinding
{
    public class WcfUnitOfWorkErrorHandler : IErrorHandler
    {
        public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
        {
            var unitOfWork = UnitOfWorkBinder.CurrentUnitOfWork;
            if (unitOfWork == null)
                return;
            
            unitOfWork.Rollback();
        }

        public bool HandleError(Exception error)
        {
            return false; //allow error to propagate
        }
    }
}